// store/modules/system.js
import { selectSystemSetting } from "@/api/setting";

const state = {
  setting: {}
}
const mutations = {
  SET_SETTING(state, payload) {
    state.setting = payload; // 更新系统设置
  }
};

const actions = {
  getInfo(context) {
    return new Promise((resolve, reject) => {
      const getSetting = selectSystemSetting();
      Promise.all([getSetting])
        .then(([res]) => {
          if (res.code === 20000) {
            context.commit("SET_SETTING", res.data);
            resolve();
          } else {
            reject(new Error("Invalid response codes"));
          }
        })
        .catch(reject);
    });
  },
};

export default {
  namespaced: true, //命名空间
  state,
  mutations,
  actions,
};
